package deatax;


import deatax.display.gui.ResourcesPanel;
import deatax.markers.Marker;
import deatax.markers.PlayerMarker;
import deatax.unit.Unit;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pson
 */
public class Improvement {
    
    /*
     * Name of this improvement
     */
    protected String name;
    protected int score;
    
//    /**
//     * type of resource produced
//     */
//    private Resource resource;
//    
//    
//    /**
//     * amount of resource produced
//     */
//    private int bonus;
    
    protected ArrayList<ResourceAmount> bonuses;
    protected ArrayList<Improvement> upgrades;
    protected ArrayList<Unit> buildUnits;
    
    protected ResourcesPanel popup;
    
    /**
     * Resource cost of building this improvement
     * key is the resource, value is the number needed
     */
    protected ArrayList<ResourceAmount> costs;

    public Improvement(String name, int score) {//, Resource resource, int bonus) {
        this.name = name;
//        this.resource = resource;
//        this.bonus = bonus;
//        this.cost = new HashMap<Resource, Integer>();
        this.upgrades = new ArrayList<Improvement>();
        this.bonuses = new ArrayList<ResourceAmount>();
        this.costs = new ArrayList<ResourceAmount>();
        buildUnits = new ArrayList<Unit>();
        this.score = score;
        
    }

    public ArrayList<Improvement> getUpgrades() {
        return upgrades;
    }
    
    public void addUpgrades(Improvement upgrade) {
        this.upgrades.add(upgrade);
    }
    
    public void addCost(Resource r, int num) {
        this.costs.add(new ResourceAmount(r, num));
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void addUnit(Unit u) {
        this.buildUnits.add(u);
    }

    public ArrayList<Unit> getUnits() {
        return buildUnits;
    }
    
    public JPanel getPopup() {
        if (popup == null) {
            popup = new ResourcesPanel();
            for (ResourceAmount ra : bonuses) {
                popup.addResource(ra);
            }
            popup.setBackground(new Color(0,0,0,128));
            popup.calculate();
        }
        return popup;
    }
//    public int getBonus() {
//        return bonus;
//    }
//
//    public void setBonus(int bonus) {
//        this.bonus = bonus;
//    }
//
//    public HashMap<Resource, Integer> getCost() {
//        return cost;
//    }
//

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    public Resource getResource() {
//        return resource;
//    }
//
//    public void setResource(Resource resource) {
//        this.resource = resource;
//    }
    
    
    public void addBonus(Resource r, int num) {
        this.bonuses.add(new ResourceAmount(r, num));
    }

    public ArrayList<ResourceAmount> getBonuses() {
        return bonuses;
    }

    public ArrayList<ResourceAmount> getCosts() {
        return costs;
    }
    
    public Marker getMarkerRenderer(Player p){
        return new PlayerMarker(p);
    }
    
}
